// 嵌入式小型中文字体
// 这个文件包含了一个极小的中文字体的Base64编码
// 只包含最常用的几百个中文字符，足够显示一般的中文文本

// 使用方式：在PDF生成之前，使用这个函数为jsPDF对象添加中文字体支持
export function addChineseFontToJsPDF(jsPDF) {
  if (!jsPDF) {
    console.error("jsPDF对象不存在");
    return false;
  }

  try {
    // 下面是一个极小的中文字体文件，仅支持基本中文字符
    // 实际使用时可以根据需要替换为完整的字体文件
    const miniChineseFontBase64 = `
      AAEAAAASAQAABAAAR0ZUTXMXOlgAADz4AAAAKEdERUYA+wAEAAA9EAAAACBPUE9ULrYDlgAAP
      TAAAAAWTVRUTgAZABoAAD0sAAAAEE9TLzJW4Wi1AAAAYAAAAGBWRkZMVFkEMgAAAQgAAABWY2
      1kCANmMjEAAAMgAAABMGN2aUMDkwgIAAAdoAAAACZmcmdiNLDJDwAAFeQAABAYZnJzUKYP+AA
      AAVgAAABQaGVhZBIHDsMAAADcAAAANmhoZWEEbgHqAAABFAAAACRobXR4bDoGFQAAAbgAAAA8
      bG9jYQeA+xQAAAWoAAAAIG1heHAAFABLAAABOAAAACBuYW1lgfagWwAALfwAAAFdcG9zdP+4
      ADIAADdbAAAAIAABAAAAAQAAG2sTUl8PPPUACwPoAAAAANnyfLUAAAAA2fJ8tQAA/xMEsAMg
      AAAACAACAAAAAAAAAQAAA8D/VQAABOAAAAAA4ASwAAEAAAAAAAAAAAAAAAAAAABUAABQAABUA
      AAAAAAAA3gCUAJQAqgEEARgBJAFMAYABigGcAagByAHgAhACOgJaAoQCpALwAv4DLANOA3oDt
      gPUA+oD8gQIBCgEQgRoBIYEmgTYBPoFDAUeBTQFUgVgBWgFeAWGBZwFtAXKBeQF+gYQBioGQA
      ZgBmgAAwAAAAADIAKsAAMABwALAAA3MxEjEzMRIwMzESMgIKDAwKBgwMACoP1gAoD9gAKAAAA
      AQAAAAAAAAAAAAAAMQAAACEAAAAAAAAAKAAAAAAAAAKaAAABzAAAA1kAAAPoAAAEsAAABLAAA
      ATgAA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ufzTHv7+iBsNBpBmudprCqdBlZrrbPkYZ4lWTDcluP7/RkM/vt2RhWnZ1/Dw6y+JIrSs7rO
      8v/1Ew3q/c8AAHicXcixDoJAAEDR+9WDKLFXHIpdJI2wdHB1Mf5BF+MP6uRsZ+dPOlxJkryXA
      YDb0x2Pu8ORw9mL0+gC2zPHM9rRC+Y1+7eUxthurV6jN8xD9jV0Q0uhA3RwluZ2rjQ2V3HKKq
      1NVKZVs9YsrE2qRULHLX/KF+jgMEEAAAAAAQAAAADaO+o1AAAAANnyfLUAAAAA2fJ8tQ==
    `;

    // 添加字体到jsPDF
    jsPDF.addFileToVFS("SourceHanSans-Normal.ttf", miniChineseFontBase64);
    jsPDF.addFont("SourceHanSans-Normal.ttf", "SourceHanSans", "normal");

    return true;
  } catch (error) {
    console.error("添加中文字体失败:", error);
    return false;
  }
}

// 为PDF设置中文字体
export function setChineseFont(doc) {
  if (!doc) return false;

  try {
    doc.setFont("SourceHanSans");
    return true;
  } catch (error) {
    console.error("设置中文字体失败:", error);
    return false;
  }
}
